package com.vmladenov.cook.ui.recipes;

import java.util.ArrayList;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ListView;

import com.vmladenov.cook.R;
import com.vmladenov.cook.core.Helpers;
import com.vmladenov.cook.core.objects.SimpleView;
import com.vmladenov.cook.ui.SimpleLinkListActivity;

public class RecipeSubCategoriesActivity extends SimpleLinkListActivity<SimpleView>
{
	private long categoryId;

	@Override
	protected void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		Intent intent = getIntent();
		Bundle bundle = intent.getBundleExtra("CATEGORY");
		categoryId = bundle.getLong("category_id");
		this.setTitle(R.string.subCategoriesRecipes);
	}

	@Override
	protected ArrayList<SimpleView> getData()
	{
		return Helpers.getDataHelper().getRecipesRepository().getRecipeSubCategories(categoryId);
	}

	@Override
	protected void onListItemClick(ListView parent, View v, int position, long id)
	{
		SimpleView category = (SimpleView) this.getListAdapter().getItem(position);
		Intent intent = new Intent(this, RecipesListActivity.class);
		Bundle bundle = new Bundle();
		bundle.putLong("category_id", category.getId());
		bundle.putInt("type", 1);
		intent.putExtra("CATEGORY", bundle);
		startActivity(intent);
	}
}
